// Copyright (C) 2005 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// 	$Id: Module.hh 321 2005-11-02 16:19:24Z richetl $	
//

#ifndef MODULE_HH
#define MODULE_HH

#include <map>
#include <cstdlib>
#include <iostream>

#ifdef LEE_BUILD
#include "Composable.hh"
#include "Container.hh"
#else
#include <lee/Composable.hh>
#include <lee/Container.hh>
#endif

namespace lee
{

  class Module : public Composable, public Container
  {
  protected:
    std::map<std::string, int> exitMap;
    Composable * startFct;
  public:
    Module() {}
    Module(std::string n, std::string t) : Composable(n,t) {}
    virtual ~Module() {}
    virtual void makeConnection(std::string leftComposable, int leftPort, std::string rightComposable);
    bool isExit(std::string compName, int exitPoint) {
      // this creates a limit on exits of 99
      char tempBuf[3];
      sprintf(tempBuf, "%d", exitPoint);
      std::string temp(tempBuf);
      std::string keyString = compName + temp;
      return(exitMap.find(keyString) != exitMap.end());
    }
    int mapExit(std::string compName, int exitPoint) {
      // this creates a limit on exits of 99
      char tempBuf[3];
      sprintf(tempBuf, "%d", exitPoint);
      std::string temp(tempBuf);
      std::string keyString = compName + temp;
      return(exitMap.find(keyString)->second);
    }      
    inline std::string getName() {return name;}
    inline Composable * getStart() {return startFct;}
    // this will get defined for each module class written by the
    // translator
    virtual void formInnerComponents(Container * cont) = 0;
  };

}

#endif // MODULE_HH

